package com.service.scheduling.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.service.dao.enums.CommonStatusEnums;
import com.service.dao.mapper.RecommendAwardConfigMapper;
import com.service.dao.model.RecommendAwardConfig;
import com.service.scheduling.service.RecommendAwardConfigService;
import com.service.scheduling.utils.MathUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@Service("recommendAwardConfigService")
public class RecommendAwardConfigServiceImpl extends ServiceImpl<RecommendAwardConfigMapper, RecommendAwardConfig> implements RecommendAwardConfigService {

    @Override
    public List<RecommendAwardConfig> listByStatus() {

        List<RecommendAwardConfig> awardConfigs = list(new QueryWrapper<RecommendAwardConfig>().lambda()
                .eq(RecommendAwardConfig::getConfigStatus, CommonStatusEnums.ACTIVE.getCode()));
        awardConfigs.forEach(item->{
            item.setReleaseMuRate(MathUtil.getRatio(item.getReleaseMuRate()));
            item.setAwardRate(MathUtil.getRatio(item.getAwardRate()));
        });
        return awardConfigs;
    }

    @Override
    public Map<Integer, RecommendAwardConfig> mapByStatus() {
        return listByStatus().stream().collect(Collectors.toMap(RecommendAwardConfig::getGenerationsNum, a -> a));
    }
}
